package com.augurit.common.system.web.org;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.action.ExtBaseAction;
import com.augurit.common.system.service.org.IOmOrgAdminService;
import com.augurit.common.system.service.org.IOmOrgService;
import com.augurit.common.system.web.org.form.OmOrgAdminForm;
import com.augurit.common.util.ExtUtils;

/**
 * 机构管理员Action类
 */
@SuppressWarnings("serial")
@Results({@Result(name = CrudActionSupport.RELOAD, location = "at-homepage-config.action", type = "redirect")})
public class OmOrgAdminAction extends ExtBaseAction{

	// Service 引用
	@Autowired
	private IOmOrgAdminService omOrgAdminService;
	
	@Autowired
	private IOmOrgService omOrgService;
	
	// 基本属性
	
	private Long id;
	private Long[] ids;
	private Page<OmOrgAdminForm> page = new Page<OmOrgAdminForm>(15);

	private Long userId;
	private String auth;					//用于接收是否允许继续授权值
	private Long[] authNewManagedOrgIds;	//用于接收新的用户可管理机构ID集合

	/**
	 * 查询用户所管理机构的记录
	 */
	public String list() throws Exception {
		ExtUtils.initPageFromExtGridParam(this.getRequest(), page);
		page = omOrgAdminService.searchAuthOrgs(page, userId);
		this.extRenderGridJson(page);
		return null;
	}
	
	/**
	 * 删除一个或多个机构管理员对象
	 */
	public String delete() throws Exception {
		omOrgAdminService.delete(ids);
		this.extRenderSuccess();
		return null;
	}
	
	/**
	 * 授权用户可管理机构权限
	 */
	public String authManagedOrgs() throws Exception{
		//授权用户ID
		Long authUserId = this.getLoginUserId();
		//被授权用户ID
		Long authedUserId = userId;
		
		omOrgService.authManagedOrgs(authUserId, authedUserId, auth, authNewManagedOrgIds);
		this.extRenderSuccess();
		
		return null;
	}
	
	// 属性getter和setter方法
	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}

	public Long[] getAuthNewManagedOrgIds() {
		return authNewManagedOrgIds;
	}

	public void setAuthNewManagedOrgIds(Long[] authNewManagedOrgIds) {
		this.authNewManagedOrgIds = authNewManagedOrgIds;
	}

	public String getAuth() {
		return auth;
	}

	public void setAuth(String auth) {
		this.auth = auth;
	}
}
